<template>
    <div id="jinji">
        <div v-if="!ismenu">
            <el-backtop></el-backtop>
            <div class="jj-title">
                {{name}}
            </div>
            <jinjicontent :jj="jj"></jinjicontent>
        </div>

        <div v-else>
            <jinjimenu ></jinjimenu>
        </div>
    </div>
</template>

<script>

    import {getJinjiTextByType, getJinjiType} from "../../network/jinji";
    import Jinjicontent from "./jinjichild/jinjicontent";
    import Jinjimenu from "./jinjimenu";

    export default {
        name: "jinji",
        components: {Jinjimenu, Jinjicontent},
        data(){
            return {
                jj:[],
                type:"",
                name:"",
                ismenu:false,

            }
        },
        created() {
            this.jinjiinit()
        },
        methods:{
            jinjiinit(){
                this.type = this.$route.params.type
                if (this.type.length ==4)
                {
                    this.ismenu = false
                    getJinjiTextByType(this.type).then(res => {
                        this.jj = res.data

                    })
                    getJinjiType().then(res => {
                        console.log(res.data);
                        for (let i = 0; i <= 6; i++) {
                            if (res.data[i].type == this.type) {
                                this.name = res.data[i].name
                            }

                        }
                    })
                }
                else{
                    this.ismenu = true
                }
            }
        },
        mounted() {
            this.$bus.$on('jmenuclick',(type)=>{
                this.ismenu = true
                this.type=type
            })
            this.$bus.$on('jtitemclick',(nt)=>{
                this.type = nt.type
                this.name = nt.name
                getJinjiTextByType(nt.type).then(res=>{
                    this.jj = res.data

                })
                })
        },
        watch:{
            '$route':'jinjiinit'
        }
    }
</script>

<style scoped>
    .jj-title{
        font-size:20px;
        color:red;
        text-align: center;
        font-family: "微软雅黑";
        margin-bottom: 10px;
    }




</style>